import matplotlib.pyplot as plt
import pandas as pd

# 假设原始的 country_mapping 映射关系字典
country_mapping = {
    "Soviet Union": "Russia",
    "Czechoslovakia": "Czech Republic",
    "East Germany": "Germany",
    "West Germany": "Germany",
    "Yugoslavia": "Serbia",
    "Unified Team": "Russia",
    "ROC": "Russia",
    "Chinese Taipei": "Taiwan",
    "Great Britain": "United Kingdom",
    "Swaziland": "Eswatini",
    "Macedonia": "North Macedonia",
    "Moscow, Soviet Union": "Russia",  # 为了准确匹配可以加上这个映射
}


# 创建映射函数
def map_country_name(name, mapping):
    return mapping.get(name, name)


# 假设 original_names 和 processed_names 是来自 medal_counts 数据集
original_names = ['Soviet Union', 'Czechoslovakia', 'East Germany', 'West Germany', 'Yugoslavia', 'Unified Team', 'ROC',
                  'Chinese Taipei', 'Great Britain', 'Swaziland', 'Macedonia']
processed_names = [map_country_name(name, country_mapping) for name in original_names]

# 创建一个 DataFrame 来表示映射关系
mapping_df = pd.DataFrame({
    'Original Name': original_names,
    'Mapped Name': processed_names
})

# 统计每个映射对的频次
mapping_counts = mapping_df.groupby(['Original Name', 'Mapped Name']).size().reset_index(name='Count')

# 创建散点图，频次作为点的大小，原始国家名称和映射国家名称作为坐标
plt.figure(figsize=(12, 8))

# 设定点的大小（通过频次）
sizes = mapping_counts['Count'] * 100  # 乘以100让点更大

# 绘制散点图
scatter = plt.scatter(mapping_counts['Original Name'], mapping_counts['Mapped Name'],
                      s=sizes, c=sizes, cmap='viridis', alpha=0.6, edgecolors="w", linewidth=0.5)

# 添加标题
plt.title('Country Name Mapping Relationships', fontsize=18, fontweight='bold')
plt.xlabel('Original Country Name', fontsize=14)
plt.ylabel('Mapped Country Name', fontsize=14)

# 调整X轴和Y轴标签旋转角度
plt.xticks(rotation=45, ha='right', fontsize=12)
plt.yticks(rotation=0, fontsize=12)

# 去掉数字标签
# plt.text(...) 代码已删除

# 去掉颜色条
# No cbar = plt.colorbar() here

plt.tight_layout()
plt.show()
